import * as types from './mutation-types'

export const selectPlay = function ({commit, state}, {list, index}) {
  // commit 去改变 mutations -- 从而改变 state  commit第二个参数是传入到了 对应函数的第二个参数位置上
  commit(types.SET_SEQUENCE_LIST, list)
  commit(types.SET_PLAYLIST, list)
  commit(types.SET_CURRENT_INDEX, index)
  commit(types.SET_FULL_SCREEN, true)
  commit(types.SET_PLAYING_STATE, true)
}

export const addSong = function({commit, state}, {song}) {
  let playList = state.playList.slice()
  let currentindex = state.currentIndex
  playList.splice(currentindex, 0, song)
  commit(types.SET_SEQUENCE_LIST, playList)
  commit(types.SET_CURRENT_INDEX, currentindex)
  commit(types.SET_PLAYLIST, playList)
  commit(types.SET_FULL_SCREEN, true)
  commit(types.SET_PLAYING_STATE, true)
}